<template>
  <!-- 租赁房产管理 -->
  <base-breadcrumb :title="$route.meta.title">
    <!-- 搜索 -->
    <searchData
      :search-data="searchArr"
      @search="search"
      @onSelectChange="change"
    />
    <!-- 表格 -->
    <a-card :bordered="false">
      <!-- <title-name :title="$route.meta.title" /> -->
      
      <!-- <excel
        ref="exportAll"
        v-btn-permission="'oa_017_exp_04'"
        :file-name="excelName"
        is-click-generate="false"
      >
        <a-button
          slot="excelBtn"
          :loading="loading"
          :disabled="totalSize < 0"
          icon="export"
          type="primary"
          @click="exportAll"
        >
          导出
        </a-button>
      </excel> -->
      <!-- 表格 -->
     <list-table
        ref="table"
        row-key="id"
        :columns="columns"
        :request="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        :export-permission="{ select: 'oa_017_exp_04', all: 'oa_017_exp_04' }"
        :export-config="{ use: true, select: `${excelName}`, all: `${excelName}` }"
      >
        <a-button
          slot="prefix" 
          slot-scope="ref"
          v-btn-permission="'oa_017_add_02'"
          class="mb12"
          icon="plus"
          type="primary"
          @click="handleManage(2)"
        >
          新增自有房产
        </a-button>
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }}</span>
        <template
          slot="operation"
          slot-scope="text, record"
        >
          <MoreButton>
          <a
            v-btn-permission="'oa_017_loo_01'"
            @click="handleManage(0, record)"
          >查看</a>
          <a
            v-btn-permission="'oa_017_edi_03'"
            @click="handleManage(1, record)"
          >编辑</a>
          <a
            class="del_btn"
            @click="handleRemoves([record.id])"
          >删除</a>
          </MoreButton>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
// import { STable } from '@/components' // 表格
import { getHomeOwnershipList, removeHomeOwnership } from '@/api/office/propertyManagement' // api
import TreeSelectOrganization from '@/components/TreeSelectOrganization'
import Selector from '@/components/Select/Selector'
import BasePage from '@/views/basePage' // 基础配置
import SelectCompanyAndProject from '@/components/Select/SelectCompanyAndProject'
import OrgTreeSelect from '@/components/OrgTreeSelect/index'
const searchArr = [
  // 搜索框
  {
    name: '单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
  {
    name: '房屋用途',
    valueKey: 'houseUseId',
    type: Selector,
    selectType: '3',
    urlType: 'office',
  },
  {
    name: '小区名称',
    type: 'input',
    value: 'placeName',
  },
  {
    name: '购房时间',
    value: 'buyHouseDay',
    type: 'dateRange',
  },
  {
    name: '状态',
    value: 'status',
    type: 'select',
    data: [
      {
        value: '0',
        label: '可用  ',
      },
      {
        value: '1',
        label: '不可用',
      },
    ],
  },
]
const columns = [
  {
    title: '序号',
    width: 80,
    dataIndex: 'index',
    scopedSlots: { customRender: 'index' }
  },
  {
    title: '单位',

    dataIndex: 'deptStr',
  },
  {
    title: '产权单位',
    ellipsis: true,
    dataIndex: 'owner',
  },
  {
    title: '小区名称',
    ellipsis: true,
    dataIndex: 'placeName',
  },
  {
    title: '房屋地址',
    ellipsis: true,
    dataIndex: 'placeAddress',
  },
  {
    title: '门牌号',
    ellipsis: true,
    dataIndex: 'houseNum',
  },

  {
    title: '建筑面积(m²)',
    ellipsis: true,
    dataIndex: 'builtArea',
    //    customRender(text, record, index) {
    //     return record.builtArea + 'm²'
    // },
  },
  {
    title: '房屋用途',
    dataIndex: 'houseUseStr',
    ellipsis: true,
  },
  {
    title: '房产原值(元)',
    dataIndex: 'houseAmount',
    //  customRender(text, record, index) {
    //     return record.houseAmount + '元'
    // },
    ellipsis: true,
  },
  {
    title: '购房时间',
    dataIndex: 'buyHouseDaye',
    ellipsis: true,
  },

  {
    title: '状态',
    dataIndex: 'statusStr',
    ellipsis: true,
  },
  {
    title: '操作',
    dataIndex: 'operation',
    width: '180px',
    align: 'center',
    scopedSlots: { customRender: 'operation' },
  },
]
export default {
  name:'a'+Date.now(),
  extends: new BasePage(),
  components: {
    // STable,
  },
  data() {
    this.columns = columns
    this.searchArr = searchArr
    return {
      loading: false,
      queryParam: {}, // 查询参数
      totalSize: 0,
      excelName:'自有房产',
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, { query: this.queryParam })
        return getHomeOwnershipList(requestParameters).then((res) => {
          this.totalSize = res.totalSize
          return res
        })
      }, // 加载数据方法 必须为 Promise 对象
      removeApi: { remove: removeHomeOwnership }, // api
      editModel: 0,
      form: {},
      position:''
    }
  },
  mounted() {
    // this.$refs.exportAll.tableToExcelFile(this.$refs.table)
    this.position = this.$currentPost()?.postCode
  },
  methods: {
    // 搜索
    search(value) {
      this.queryParam = {
        ...value,
        buyHouseDayeStart:
          (value.buyHouseDay &&
            value.buyHouseDay.length &&
            value.buyHouseDay[0].format('YYYY-MM-DD HH:mm:ss')) ||
          void 0,
        buyHouseDayeEnd:
          (value.buyHouseDay &&
            value.buyHouseDay.length &&
            value.buyHouseDay[1].format('YYYY-MM-DD HH:mm:ss')) ||
          void 0,
      }

      this.$refs.table.refresh(true)
    },
    change(e){
      console.log(e)
      this.excelName = e.name+"房产管理台账"
    },
    /*
     * 导出所有的数据
     * */
    exportAll() {
      // 参数：查询条件、导出的回调
      if (this.totalSize) {
        this.list(false, this.$refs.exportAll.setDataAndGenerate)
      } else {
        this.$message.warning('没有可导出的数据')
      }
    },
    list(params, callback) {
      this.loading = true
      let _this = this
      let searchData = Object.assign(
        {
          pageSize: this.totalSize,
          pageNo: 1,
        },
        params,
        this.queryParam
      )

      getHomeOwnershipList(searchData).then((res) => {
        if (res.code === 200) {
          if (callback) {
            if (res.data.length) {
              callback(res.data)
            } else {
              this.$message.warning('没有可导出的数据')
            }
            this.loading = false
            return
          }
          _this.tableData = res.data
          _this.totalSize = res.totalSize
        }
        this.loading = false
      })
    },
    // 操作栏
    handleManage(type, record) {
      this.editModel = type
      let query = {
        editModel: type,
      }
      if (record && record.id) {
        query.id = record.id
      }
      this.$router.push({
        name: '/office/propertyManagement/homeOwnership/updateHomeOwnership',
        query,
      })
    },
  },
}
</script>
